package com.library.librarybackend.domain;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

/**
 * @author 平
 * @description 分页响应结果
 * @since 2025-09-21 20:59
 */
@Data
public class ResponseWithPage<T> {

    @Schema(description = "数据")
    private List<T> data;

    @Schema(description = "页码")
    private Long page;

    @Schema(description = "每页数量")
    private Long pageSize;

    @Schema(description = "数据总数")
    private Long total;

    public static <T> ResponseWithPage<T> of(IPage<T> page) {
        ResponseWithPage<T> responseWithPage = new ResponseWithPage<>();
        responseWithPage.setData(page.getRecords());
        responseWithPage.setPage(page.getCurrent());
        responseWithPage.setPageSize(page.getSize());
        responseWithPage.setTotal(page.getTotal());
        return responseWithPage;
    }

}
